package com.rtf.framework.web.mvc.config.web.configurer.support;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class AppLongToStringSerializer extends ToStringSerializer {

    public final static AppLongToStringSerializer appInstance = new AppLongToStringSerializer();

    public static final int JS_MAX_LENGTH  = 16 ;

    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        if( value != null && value instanceof Long && value.toString().length() < JS_MAX_LENGTH ){
            gen.writeNumber( (Long) value ) ;
        }else{
            super.serialize(value, gen, provider) ;
        }
    }
}
